package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.utils.DateTimeController;
import com.jxwifi.cloud.quickclean.utils.MultiWheelView;
import com.popwindow.BasicPopmodule;

public class PopTimeChoiceModule extends BasicPopmodule {

    private Context mContext;
    private PopTiemListener mPoplistener;
    private DateTimeController mController;//自定义控件


    public PopTimeChoiceModule(Context context,int mStartsTime,int mTimeInterval,int mEndTime, PopTiemListener l) {
        this.mContext = context;
        this.mPoplistener = l;
        mController = new DateTimeController(mStartsTime,mTimeInterval,mEndTime);
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_show_time_choice, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        View mVwPopBlank=(View)mContentView.findViewById(R.id.vw_pop_blank);
        TextView mTvTimeChoiceCancel=(TextView)mContentView.findViewById(R.id.tv_time_choice_cancel);
        TextView mTvTimeChoiceDetermine=(TextView)mContentView.findViewById(R.id.tv_time_choice_determine);
        MultiWheelView mMvpopDateChoose=(MultiWheelView)mContentView.findViewById(R.id.mv_pop_date_choose);
        mVwPopBlank.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mTvTimeChoiceCancel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mTvTimeChoiceDetermine.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {

                String newTimes=mController.mDatas1.get(mController.getCurrentValues()[0]).toString();
                String newTimes1=mController.mDatas2.get(mController.getCurrentValues()[1]).toString().replace("时","");
                String newTimes2=mController.mDatas3.get(mController.getCurrentValues()[2]).toString().replace("分","");
                mPoplistener.Determine(newTimes+" "+newTimes1+":"+newTimes2);
                Log.w("oushuhua","日期 "+newTimes+"小时 "+newTimes1+"分钟 "+newTimes2);
                mPopwindows.dismiss();
            }
        });
        mController.setScrollLinked(true);
        mMvpopDateChoose.bindController(mController);

    }

    public interface PopTiemListener {
        void Determine(String OrderTime);

    }
}
